{extend name="public/base"}

{block name="title"}添加广告{/block}

{block name="main"}
<!--添加用户UI-->
<div class="layui-row">
    <div class="layui-col-md4 layui-col-md-offset4">
        <form action="{:url('/adv')}" method="post" class="layui-form layui-form-pane">
            <div class="layui-form-item layui-form-text">
                <label for="text" class="layui-form-label">广告文字(支持html语句)</label>
                <div class="layui-input-block">
                    <textarea name="text" id="text"  placeholder="请输入内容(支持html语句)" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="img" class="layui-form-label">广告图片</label>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn layui-btn-fluid" id="test1">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                        <input type="hidden" name="img" id="img">
                    </button>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-md12">
                    <img src="" width="100%" height="120px"  class="layui-upload-img" id="demo1" alt="这是广告图片">
                </div>
            </div>
            <div class="layui-form-item" >
                <label for="url" class="layui-form-label">广告链接</label>
                <div class="layui-input-block">
                    <input type="text"  required   id="url" name="url" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">广告位置</label>
                <div class="layui-input-block">
                    <select name="position" id="position" class="form-control w-50  col-form-label">
                        <option value="1" selected>顶部图片</option>
                        <option value="2">顶部文字</option>
                        <option value="3">底部</option>
                        <option value="4">浮动</option>
                        <option value="5">开奖栏(文字)</option>
                        <option value="6" >算法栏(文字)</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class=" layui-form-label">是否图片广告</label>
                <div class="layui-input-block">
                    <select name="is_img" id="is_img" class="form-control w-50  col-form-label">
                        <option value="2" selected>否</option>
                        <option value="1" >是</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <a href="{:url('/adv')}" class="layui-btn layui-btn-normal  layui-btn-sm"><i class="layui-icon layui-icon-left"></i>返回列表</a>
            </div>
            <div class="layui-form-item">
                <input type="hidden" value="{:token()}" name="__token__">
                <button class="layui-btn layui-btn-success layui-btn-fluid layui-btn-lg">提交添加</button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['upload','layer','jquery','form'], function(){
        var upload = layui.upload,
        layer = layui.layer,
            $=layui.$;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: "{:url('index/upload')}" //上传接口
            ,field:'image'
            ,accept: 'image'
            ,acceptMime:'image/*'
            ,before:function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
                layer.msg('上传中', {icon: 16, time: 0});
            }
            ,done: function(res){
                //上传完毕回调
                if (res.code===200){
                    layer.msg(res.msg,{
                        icon:1
                    })
                    $('#img').val(res.path)
                }else{
                    layer.msg(res.msg,{
                        icon:2
                    })
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
</script>
{/block}